'''
Created on Apr 5, 2009

@author: Administrator
'''
from com.ericyang.groupshopping.company.models import Company
from django.db import models
from django.contrib.auth.models import User

USER_FLAG = (
          ('0', 'user'),
          ('1', 'company'),
    )
class UserDetail(User):
    nickname = models.CharField(max_length=20, null=False)
    userFlag = models.CharField("user flag", max_length=10, choices=USER_FLAG)
    #user = models.OneToOneField(User)
    company = models.OneToOneField(Company, null=True, blank=True)
    
    def is_common_user(self):
        return self.userFlag == '0'
    
    def is_company_user(self):
        return self.userFlag == '1'
    
    def company_name(self):
        queryset = Company.objects.filter(user__id=self.id)
        if queryset and queryset.count() > 0:
             return queryset[0].name
        return None

    
